package cn.yangliu.oauth2.web;

import cn.yangliu.oauth2.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author 杨柳
 * @date 2019-04-17
 */
@RestController
@Api
public class UserController {

    @GetMapping("/openId")
    @ApiOperation("openId")
    public String openId(@ApiIgnore Authentication authentication){
        User user = (User) authentication.getPrincipal();
        return user.getId().toString();
    }

    @GetMapping("/principal")
    @ApiOperation("principal")
    public Object principal(@ApiIgnore Authentication authentication){
        return  authentication.getPrincipal();
    }
}
